package cn.bitkit.tools.common;

import java.util.ArrayList;
import java.util.List;

/**
 * @author changbo
 */
public class ListUtil {

    public static <T> List<List<T>> split(List<T> list, int size){
        List<List<T>> res = new ArrayList<>();
        if(list == null || list.isEmpty()){
            return res;
        }
        int length = list.size() / size;
        length = list.size() % size == 0 ? length : length + 1;
        for(int i = 0; i<length; i++){
            int start = i * size;
            int end = Math.min((i+1) * size, list.size());
            List<T> part = new ArrayList<>(list.subList(start, end));
            res.add(part);
        }
        return res;
    }


}
